package com.zhihuishu.treenity.controller.tools;

import javax.annotation.Resource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.zhihuishu.remote.RemoteException;
import com.zhihuishu.remote.RemoteResult;
import com.zhihuishu.treenity.controller.BaseController;
import com.zhihuishu.treenity.dto.ImageDto;
import com.zhihuishu.treenity.log.LoggerCollectionEnum;
import com.zhihuishu.treenity.service.tools.ImageCutService;
import com.zhihuishu.treenity.util.DataSource;

/**
 * 图片裁剪工具
 * @author JinXing
 * @date 2016年12月29号 上午9:04
 * */
@Controller
@RequestMapping("/tools")
public class ImageCutController extends BaseController{

	@Resource 
	private ImageCutService imageCutService;
	
	
	/**
	 * 全图裁剪 （在原图的基础上进行裁剪）
	 * @param dto
	 *	 url	 //原图的网络地址
	 *	 leftX	 //裁剪区域左边X轴
	 *	 leftY	 //裁剪区域左边Y轴
	 *	 rightX	 //裁剪区域右边X轴
	 *	 rightY	 //裁剪区域右边Y轴
	 *	 width	 //裁剪区域宽度
	 *	 height	 //裁剪区域高度
	 *   cutType //裁剪类型  （1.原图裁剪  2.指定的宽高比例裁剪）
	 *   
	 * @param dealtWidth  //裁剪区域定义的宽度  (cutType=2需要传)
	 * @param dealtHeight //裁剪区域定义的高度  (cutType=2需要传)
	 */
	
	@ResponseBody
	@RequestMapping(value = "fullImageCut")
	public RemoteResult<DataSource> fullImageCut(final ImageDto dto,final Double dealtWidth,final Double dealtHeight){

		 RemoteResult<DataSource> result = new ResultRequestAndParser<DataSource>("图片裁剪", "imageCut", "全图裁剪", "fullImageCut") {
	            @Override
	            public RemoteResult<DataSource> request(Long curUserId) throws RemoteException {
	            		RemoteResult<DataSource> rs = imageCutService.ImageCut(dto,dealtWidth,dealtHeight);
		            	return rs;
	            }
	        }.get();
	        
	   return result;		
	}
	
	/**
	 * log 存入的表
	 */
	@Override
	protected LoggerCollectionEnum getCollectionEnum(){
        return LoggerCollectionEnum.toolsCollection;
    }
	
}
